//
//  LCComposeTextView.swift
//  Swift0319
//
//  Created by admin on 2017/3/29.
//  Copyright © 2017年 __MyCompanyName__. All rights reserved.
//

import UIKit
import SVProgressHUD

class LCComposeTextView: UITextView {

    override var font: UIFont? {
        didSet{
            
        }
    }
    var placeholder: String?{
        didSet{
            placeholderLabel.text = placeholder
        }
    }
    override init(frame: CGRect, textContainer: NSTextContainer?) {
        super.init(frame: frame, textContainer: textContainer)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //FIXME:- 上午10:29 设置视图
    ///设置视图
    private func setupUI(){
        addSubview(placeholderLabel)
        placeholderLabel.snp.makeConstraints { (make) in
            make.left.equalTo(5)
            make.top.equalTo(8)
            make.width.equalTo(ScreenWidth - 10)
        }
        
        //FIXME:-/ 注册系统通知监听textView文字改变
        utils.textFiledComposeEditChanged()
        weak var ws = self
        utils.composeEditBlock = {
            ws!.placeholderLabel.isHidden = ws!.hasText
        }
    }
    fileprivate lazy var placeholderLabel: UILabel = {
        let lab = UILabel()
        self.setupPlaceholderLabel(lab)
        return lab
    }()
    
    deinit {
        NotificationCenter.default.removeObserver(self)
    }
    
    lazy var utils : LCUtils = {
        let utils = LCUtils()
        return utils
    }()
}
extension LCComposeTextView {
    @objc fileprivate func textViewTextDidChange(){
        placeholderLabel.isHidden = self.hasText
    }
    
}
extension LCComposeTextView {
    fileprivate func setupPlaceholderLabel(_ lab : UILabel){
        lab.textColor = UIColor.lightGray
        lab.numberOfLines = 0
    }
}
